package com.ynny.controller;

import com.ynny.dao.UserDao02;
import com.ynny.entity03.R;
import com.ynny.entity03.UserDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user1")
public class UserController02 {
    @Autowired
    UserController02 userController02;
    @Autowired
    UserDao02 userDao02;

    @PostMapping("/register")
    public R register(@RequestBody UserDTO user) {


        System.out.println(user);

        if (user.getUsername() == null || user.getPassword() == null) {
            return R.fail(201, "用户名或密码不能为空");
        }
        //注册是一个业务功能
        int res = userDao02.addUser(user);

        if (res == 200) {
            return R.ok(user);
        } else if (res == 211) {
            return R.fail(211, "用户名已存在");
        }
        return R.ok(null);
    }

}












